package com.sduept.nwld.dataview.controller.message;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.sduept.bigdata.risk.service.RiskAlarmMessageQueryManager;
import com.sduept.bigdata.web.jsf.controller.AbstractController;
import com.sduept.core.ParamManager;
import com.sduept.message.entity.AlarmMessage;
import com.sduept.message.manager.MessageReceiveConfigManager;
import com.sduept.message.manager.MessageTypeManager;
import com.sduept.permission.entity.PersonnelEntityBean;

@Named
@ViewScoped
public class WebAlarmMessageReciveController extends AbstractController {

	private static final long serialVersionUID = -1853164291560116662L;
	@Autowired
	private MessageReceiveConfigManager relation;
	@Autowired
	private RiskAlarmMessageQueryManager risk;
	@Autowired
	private MessageTypeManager type;
	@Autowired
	private ParamManager pc;

	private PersonnelEntityBean user = null;
	private List<AlarmMessage> alarms = null;

	@PostConstruct
	private void init() {
		user = getCurrentUser();
		if (user != null) {
			initTable();
		} else {
			addErrorMessage("请先登录系统");
		}
	}

	public void initTable() {
		String userCode = user.getCode();
		List<String> typeIds = relation.listTypes(userCode, "web");
		// alarms = risk.listBytypeids(typeIds);
		alarms = risk.getAlarmMessageByTypes(typeIds);
	}

	public String getTypeDescription(String typeId) {
		return (pc.get(typeId) != null && StringUtils.isNotEmpty(pc.get(typeId).getDescription())) ? pc.get(
				typeId).getDescription() : "";
		// return type.getTypeDescription(typeId);
	}

	public List<AlarmMessage> getAlarms() {
		return alarms;
	}

	public void setAlarms(List<AlarmMessage> alarms) {
		this.alarms = alarms;
	}

}
